
package com.kaciula.letsdoit.ui;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.kaciula.letsdoit.R;
import com.kaciula.letsdoit.db.WastesDbAdapter;

import android.graphics.drawable.Drawable;
import android.os.Bundle;

public class WasteMapActivity extends MapActivity {

    private static final int ZOOM_LEVEL = 13;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.waste_map);

        MapView mapView = (MapView) findViewById(R.id.waste_map);
        mapView.setBuiltInZoomControls(true);

        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            long id = extras.getLong(WastesDbAdapter.KEY_ROWID);
            double lat = extras.getDouble(WastesDbAdapter.KEY_LAT);
            double longitude = extras.getDouble(WastesDbAdapter.KEY_LONG);

            GeoPoint point = getPoint(lat, longitude);
            mapView.getController().setCenter(point);
            mapView.getController().setZoom(ZOOM_LEVEL);

            Drawable marker = getResources().getDrawable(R.drawable.ic_marker);
            WastesOverlay wastesOverlay = new WastesOverlay(marker, this);

            OverlayItem item = new OverlayItem(point, getString(R.string.waste) + " " + id, "");
            wastesOverlay.addOverlay(item);
            mapView.getOverlays().add(wastesOverlay);
        }
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    private GeoPoint getPoint(double lat, double lon) {
        return (new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0)));
    }
}
